Assement2

Data Analysis

# Load packages
library(ggspatial)
library(sf)
library(sfhotspot)
library(readr)
library(readxl)
library(tidyverse)

Data preparation

# Read the data
london_crimes <- read.csv("london_crimes.csv") |>
  st_as_sf(coords = c("longitude", "latitude"), crs = 4326) %>%
  st_transform(crs = "EPSG:27700")

# Define the boroughs in the North West BCU
north_west_boroughs <- c("Brent", "Barnet", "Harrow")

london_ward <- st_read("ESRI/London_Ward.shp") |>
  st_transform(crs = "EPSG:27700")
Reading layer `London_Ward' from data source 
  `/Users/duke/Desktop/map_data/ESRI/London_Ward.shp' using driver `ESRI Shapefile'
Simple feature collection with 649 features and 7 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: 503568.2 ymin: 155850.8 xmax: 561957.5 ymax: 200933.9
Projected CRS: OSGB36 / British National Grid
# Filter the london_ward dataset to include only the wards in these boroughs
north_west_wards <- london_ward |>
  filter(BOROUGH %in% north_west_boroughs) 

# Keep only crimes within the South West wards
nw_crimes <- london_crimes %>%
  st_join(north_west_wards, join = st_intersects, left = FALSE)

# Calculate KDE for the South West BCU crimes
nw_crime_density <- nw_crimes %>%
  hotspot_kde(bandwidth_adjust = 0.2, quiet = TRUE) |>
  st_transform(crs = "EPSG:27700")

# Clip the density layer to the South West wards boundaries
nw_crime_density_clip <- st_intersection(nw_crime_density, north_west_wards)

# Calculate centroids for the boroughs
borough_boundaries <- north_west_wards %>%
  group_by(BOROUGH) %>%
  summarise(geometry = st_union(geometry)) %>%
  ungroup()

KDE map analysis for overall crime in north west BCU

# Plot the KDE map for the South West BCU
ggplot() +
  annotation_map_tile(type = "cartolight", zoomin = 0, progress = "none") +
  geom_sf(aes(fill = kde), data = nw_crime_density_clip, alpha = 0.75, colour = NA) +
  geom_sf(data = north_west_wards, colour = "grey", fill = NA) +
  geom_sf(data = borough_boundaries, fill = NA, colour = "black", size = 1.2) +
  geom_sf_label(
    aes(label = BOROUGH), 
    data = borough_boundaries, 
    alpha = 0.5, 
    colour = "seagreen", 
    lineheight = 1, 
    size = 2.5, 
    label.size = NA
  ) +
  scale_fill_distiller(direction = 1) +
  theme_void() +
  labs(
    title = "Concentration of Crimes in the North West BCU (2022)",
    subtitle = "KDE showing areas of high crime concentration",
    caption = "Data Source: London Crime Data"
  ) +
  theme(legend.position = "right")

The figure above uses kernel density estimation (KDE) to show the distribution of crime concentrations in the Northwest BCU for 2022. The darker the color, the higher the crime concentration. The map indicates that parts of the Brent and Barnet districts are high-incidence areas for crime. In Brent, crime hotspots are primarily concentrated in the southern and southeastern areas of the district. In Barnet, hotspots are mainly found in the central and southern areas, particularly near the border between Finchley Central and Brent. These areas are close to major transportation hubs and commercial zones, where criminal activities are frequent. Therefore, it is essential to strengthen police deployment and monitoring facilities in these hotspots.

Which type of crime should be focused on ?

# Count the occurrences of each crime type
nw_crime_type_counts <- nw_crimes %>%
  group_by(type) %>%
  summarise(count = n()) %>%
  arrange(desc(count))

# Create a bar plot to visualize the crime types in the North West BCU
ggplot(nw_crime_type_counts, aes(x = reorder(type, count), y = count)) +
  geom_bar(aes(fill = count), stat = "identity") +
  geom_text(aes(label = count), hjust = -0.1, cex = 1.75) +
  scale_fill_gradient(low = "cornflowerblue", high = "mediumblue") +
  coord_flip() + 
  labs(
    title = "Distribution of Crime Types in the North West BCU (2022)",
    x = "Crime Type",
    y = "Number of Incidents"
  ) +
  theme_minimal() +
  theme(legend.position = "none", plot.title = element_text(hjust = 1))

This chart shows the distribution of different crime types within the Northwest BCU in 2022. The bar chart indicates that “violent or sexual crime” and “vehicle crime” are the two main types of crime, with significantly higher numbers of incidents compared to other types, and this suggests that these crimes should receive more attention and stricter enforcement in the area. In contrast, crime types such as “bicycle theft” and “weapon possession” have fewer incidents, and police force can

Hotspots map to show ward with most crimes in each brough

# Calculate the number of incidents per ward within each borough in the North West BCU
ward_counts_nw <- nw_crimes %>%
  st_join(north_west_wards) %>%
  st_drop_geometry() %>%
  group_by(BOROUGH.x, NAME.x) %>%  
  summarise(incident_count = n()) 

# Identify the ward with the highest number of incidents in each borough
top_wards_per_borough <- ward_counts_nw %>%
  group_by(BOROUGH.x) %>%
  slice_max(order_by = incident_count, n = 1)

# Filter the wards data to include only the top wards in each borough
hotspot_wards_nw <- north_west_wards %>%
  inner_join(top_wards_per_borough, by = c("NAME" = "NAME.x"))
# Plot the KDE map for the South West BCU
ggplot() +
  annotation_map_tile(type = "cartolight", zoomin = 0, progress = "none") +
  geom_sf(data = hotspot_wards_nw, fill = "red", alpha = 0.75) +
  geom_sf(data = north_west_wards, colour = "grey", fill = NA) +
  geom_sf(data = borough_boundaries, fill = NA, colour = "black", size = 1.2) +
  geom_sf_label(
    aes(label = BOROUGH), 
    data = borough_boundaries, 
    alpha = 0.5, 
    colour = "seagreen", 
    lineheight = 1, 
    size = 4, 
    label.size = NA
  ) +
  geom_sf_label(
    aes(label = NAME), 
    data = hotspot_wards_nw, 
    alpha = 0.5, 
    colour = "red", 
    lineheight = 1, 
    size = 2.5, 
    label.size = NA
  ) +
  scale_fill_distiller(direction = 1) +
  theme_void() +
  labs(
    title = "Concentration of Crimes in the North West BCU (2022)",
    subtitle = "Hotspots showing wards with most crimes in each brough",
    caption = "Data Source: London Crime Data"
  ) +
  theme(legend.position = "right")

This chart shows the distribution of crime hotspots within the Northwest BCU in 2022, highlighting the wards with the highest crime rates in each borough. As can be seen above, Stonebridge in Brent, Colindale in Barnet, and Greenhill in Harrow are crime hotspots within their respective boroughs. The red areas clearly identify these high crime wards, which is consistent with the previous KDE density plot.

Which location type of crime should be focused on ?

# Count the occurrences of each crime type
nw_crime_location_counts <- nw_crimes %>%
  group_by(location_type) %>%
  summarise(count = n()) %>%
  arrange(desc(count)) %>%
  na.omit()

# Create a bar plot to visualize the crime types in the North West BCU
ggplot(nw_crime_location_counts, aes(x = reorder(location_type, count), y = count)) +
  geom_bar(aes(fill = count), stat = "identity") +
  geom_text(aes(label = count), hjust = -0.1, cex = 2) +
  scale_fill_gradient(low = "cornflowerblue", high = "mediumblue") +
  coord_flip() + 
  labs(
    title = "Distribution of Crime Location in the North West BCU (2022)",
    x = "Crime Location Type",
    y = "Number of Incidents"
  ) +
  theme_minimal() +
  theme(legend.position = "none", plot.title = element_text(hjust = 1))

Among known crime locations, supermarkets, parking lots and LU stations are the top three locations with the most crime incidents, indicating that these areas should be the focus of increased security measures and police deployment. This also implies the importance of concentrating resources in locations with high traffic and high crime rates.